﻿@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums.InsuranceProducts
@model ZBJF.Warranty.Model.ViewModel.Order.InsuranceOrderModel
@{
    ViewBag.Title = "保险卡列表";
}
<link href="~/Content/layout.css" rel="stylesheet" />
<div class="desc_forward_title" onclick="history.back(-1)">
    选择您的专属保险方案
</div>
<div id="productList" class="zbjf-product-list">
</div>
<div class="weui-loadmore" style="display: none">
    <i class="weui-loading"></i>
    <span class="weui-loadmore__tips">上拉加载更多数据</span>
</div>
<div class="zbjf-product-nomore" style="display: none">
    <div class="left">
        <hr>
    </div>
    <div class="center-text">没有更多数据了</div>
    <div class="right">
        <hr>
    </div>
</div>
<div class="weui-form-preview__ft weui-footer_fixed-bottom">
    <div class="weui-form-preview__btn weui-form-preview__btn_primary">
        <div style="float: left; flex: 1; padding-left: 20%;">@Model.ProductBrandName</div>
        <div style="padding-right: 20%" class="float-right align-right">@Model.ProductModelName</div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        var iDisplayLength = parseInt((document.documentElement.clientHeight) / 150);
        var currentPageIndex = 0;
        var loading = false;  //状态标记
        $(document.body).infinite(111).on("infinite", function () {
            if (loading) return;
            loading = true;
            $.ajax({
                url: "/InsuranceProduct/GetProductCard?ProductAmount=@(Model.ProductAmount)&SellerId=@Model.SellerID&SellerEmployeeId=@Model.SellerEmployeeID",
                type: "post",
                data: { iDisplayStart: currentPageIndex * iDisplayLength, iDisplayLength: iDisplayLength },
                success: function (result) {
                    loading = false;
                    currentPageIndex++;
                    var html = "";
                    if (result && result.sellerInsuranceProductsList && result.sellerInsuranceProductsList.length > 0) {
                        for (var i = 0; i < result.sellerInsuranceProductsList.length; i++) {
                            var item = result.sellerInsuranceProductsList[i];
                            html += "<a href='/InsuranceOrder/CreateInsuranceOrder?id=" + item.ID + "'>";
                            html += '<div class="product-item">';
                            html += '<img class="product-list-imgage" src="' + item.FirstImagePath + '"/>';
                            html += '<div class="zbjf-product-content"><div class="title">';
                            html += item.ProductName + '</div>';
                            html += "<div class='weui-media-box__desc'>" + item.Tags + "</div>";
                            html += '<div class="sale-condition"><div class="price">';
                            html += "¥<span class='money'>" + item.SaleRetailPrice + "</span></div>";
                            html += '<div class="saleNum">销量';
                            html += item.SellerInsuranceProductSaleCount + '份</div>';
                            html += "</div></div></div></div></a>";
                        }
                    }
                    $('#productList').append(html);
                    if (result.isLastPage) {
                        $(document.body).destroyInfinite();
                        $('.weui-loadmore').hide();
                        $('.zbjf-product-nomore').show();
                    } else {
                        if (currentPageIndex >= 1)
                            $('.weui-loadmore').show();
                    }
                    $("#totalSaleProduct").text(result.total);
                }
            });
        });
        $(document.body).trigger("infinite");
    })
</script>
